package simulator;

import simulator.processes.Process;

/**
 * Trida oddedena od tridy <code>Process</code> reprezentujici objednavku.
 *
 */
public class Order extends Process {

	/**
	 * Konstanta maximalni povolene zpozdeni doruceni objednavky.
	 */
	public static final int		MAX_UNLOAD_DELAY = 1800;
	
	private City owner = null;
	private int goodsCount;
	private Company company;
	private Truck truck;
	
	/**
	 * Vrati mesto, ktere zadalo objednavku.
	 * @return Zadavatel objednavky.
	 */
	public City getOwner() {
		return owner;
	}

	/**
	 * Nastavi mesto, ktere zadalo tuto objednavku.
	 * @param owner Zadavatel objednavky.
	 */
	public void setOwner(City owner) {
		this.owner = owner;
	}

	/**
	 * Vrati mnozstvi objednaneho zbozi.
	 * @return Mnozstvi objednaneho zbozi.
	 */
	public int getGoodsCount() {
		return goodsCount;
	}

	/**
	 * Nastavi mnozstvi objednaneho zbozi.
	 * @param goodsCount Mnozstvi objednaneho zbozi.
	 */
	public void setGoodsCount(int goodsCount) {
		this.goodsCount = goodsCount;
	}

	/**
	 * Vrati instanci firmy, ktera vyrizuje tuto objednavku.
	 * @return Instance firmy vyrizujici tuto objednavku.
	 */
	public Company getCompany() {
		return company;
	}

	/**
	 * Nastavi instanci firmy, ktera vyrizuje tuto objednavku.
	 * @param company Firma vyrizujici tuto objednavku.
	 */
	public void setCompany(Company company) {
		this.company = company;
	}
	
	/**
	 * Vrati instanci prirazeneho nakladaku teto objednavce.
	 * @return Nakladak prirazeny teto objednavce.
	 */
	public Truck getTruck() {
		return truck;
	}

	/**
	 * Pripradi nakladak objednavce.
	 * @param truck Nakladak, ktery ma byt prirazen objednavce.
	 */
	public void setTruck(Truck truck) {
		this.truck = truck;
	}

	@Override
	protected void process() {
		notifyProcessed();
		company.processOrder(this);
	}
	
	@Override
	public String toString() {
		return "ID: " + getId() + ", Mesto: " + owner.getIndex() + ", Pocet palet: " + goodsCount;
	}
}
